package br.uvv.sao.dao;

import java.util.List;

import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import br.uvv.sao.domain.Disciplina;
import br.uvv.sao.util.DAOException;

@SuppressWarnings("unchecked")
public class DisciplinaDAO extends DAO {
	
	private static final long serialVersionUID = -2309787769157825024L;

	public void salvar(Disciplina disciplinaInstance) throws DAOException {
		save(disciplinaInstance, disciplinaInstance.getId());
	}
	
	public void excluir(Disciplina disciplinaInstance) throws DAOException {
		delete(Disciplina.class, disciplinaInstance.getId());
	}
	
	public List<Disciplina> listar(String codigo, String nome) throws DAOException {
		Criterion[] filtros = {
				Restrictions.ilike("nome", "%" + nome + "%"),
				Restrictions.ilike("codigo", "%" + codigo + "%")
		};
		return list(Disciplina.class, null, Order.asc("nome"), filtros);
	}
	
	public List<Disciplina> listar() throws DAOException {
		return list(Disciplina.class, null, Order.asc("nome"));
	}
	
	public Disciplina get(Long id) throws DAOException {
		return (Disciplina) get(Disciplina.class, id);
	}
	
	public Integer listarUltimoIndice() throws DAOException {
		return rowCount(Disciplina.class);
	}
}